#include <bits/stdc++.h>
#define re register
#define int long long
#define chmin(a,b) (a = min(a,b))

using namespace std;

const int N = 1e6 + 10;
const int inf = (int)(1e18) + 10;
int n,C;
int arr[N];

inline int read(){
    int r = 0,w = 1;
    char c = getchar();
    while (c < '0' || c > '9'){
        if (c == '-') w = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9'){
        r = (r << 3) + (r << 1) + (c ^ 48);
        c = getchar();
    }
    return r * w;
}

namespace Sub1{
    int ans = inf,sum[N];

    inline bool check(){
        for (re int i = 2;i <= n;i++){
            if (arr[i] < arr[i - 1]) return false;
        } return true;
    }

    inline void solve(){
        for (re int i = 1;i <= n;i++) sum[i] = sum[i - 1] + arr[i];
        for (re int i = 0;i <= n;i++) chmin(ans,arr[i] * i - sum[i] + (n - i) * C);
        printf("%lld",ans);
    }
}

namespace Sub2{
    vector<int> pt;
    int r,dp[2][N];

    inline void solve(){
        for (re int i = 1;i <= n;i++){
            pt.push_back(arr[i]);
            if (arr[i]) pt.push_back(arr[i] - 1);
        } sort(pt.begin(),pt.end());
        pt.erase(unique(pt.begin(),pt.end()),pt.end());
        const int m = pt.size();
        for (re int i = 1;i <= n;i++){
            r ^= 1;
            for (re int j = 1;j <= m;j++){
                if (pt[j - 1] >= arr[i]) dp[r][j] = dp[r ^ 1][j] + pt[j - 1] - arr[i];
                else dp[r][j] = dp[r ^ 1][j] + C;
            }
            for (re int j = m - 1;j;j--) chmin(dp[r][j],dp[r][j + 1]);
        } printf("%lld\n",dp[r][1]);
    }
}

signed main(){
    freopen("minimize.in","r",stdin);
    freopen("minimize.out","w",stdout);
    n = read(),C = read();
    for (re int i = 1;i <= n;i++) arr[i] = read();
    if (!C) puts("0");
    else if (Sub1::check()) Sub1::solve();
    else Sub2::solve();
    return 0;
}

/*
性质 1：若 b[i - 1] < a[i]，则 b[i] = b[i - 1]

*/